package org.kalai.unifypay;

import java.util.HashMap;
import java.util.Map;

import javax.websocket.Session;
/**
 * WebSocket 会话封装
 * @author Renne66
 *
 */
public class SessionManager {
	private static SessionManager sessionManager = new SessionManager();
	private Map<String, Session> sessionMap = new HashMap<>();
	private SessionManager() {}

	public static SessionManager getInstance(){
		return sessionManager;
	}
	
	public void addSession(String tranxSN, Session session) {
		sessionMap.put(tranxSN, session);
	}
	
	public void removeSession(String tranxSN) {
		sessionMap.remove(tranxSN);
	}
	
	public void broadcast(String tranxSN, String msg){
		try {
			if (sessionMap.get(tranxSN) != null)
				sessionMap.get(tranxSN).getBasicRemote().sendText(msg);
		} catch (Exception e) {
		}
	}
}
